<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateOrderSplite extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        return ;
        for ($i = 0; $i <= 99; $i++) {

            $name = str_pad($i, 3, 0, STR_PAD_LEFT);

            Schema::connection("mysqlOrder")->create('order_' . $name, function (Blueprint $table) use($name) {
                $table->unsignedBigInteger('orderId');
                $table->unsignedInteger("brandId")->default(0)->comment("品牌 Id");
                $table->unsignedInteger("shopId")->default(0)->comment("店铺 ID");
                $table->unsignedInteger("userId")->default(0)->comment("用户 ID");
                $table->string('platformId', 50)->default('')->comment('用户平台id 微信：unionid 支付宝 openid');
                $table->tinyInteger("sourceType")->default(1)->comment("订单来源 1:pos 2:小程序");
                $table->integer("serialNum")->default(0)->comment("流水号");
                $table->integer("originalPrice")->default(0)->comment("原价");
                $table->integer("shouldPrice")->default(0)->comment("应收");
                $table->integer("discountPrice")->default(0)->comment("优惠价格");
                $table->integer("payPrice")->default(0)->comment("实收");
                $table->integer("couponPrice")->default(0)->comment("优惠券优惠的价格");
                $table->integer("refundMoney")->default(0)->comment("退款总金额");
                $table->unsignedTinyInteger('payChannel')->default(0)->comment("支付渠道 1支付宝直连  2微信直连 3富有支付宝");
                $table->unsignedTinyInteger('payAction')->default(0)->comment('支付操作类型 1用户主扫 2用户被扫 3 小程序直接扫码付款');
                $table->integer("completeTime")->default(0)->comment("订单完成时间");
                $table->tinyInteger("orderStatus")->default(0)->comment("订单状态 0 待支付 1 待制作 2 待取餐 3 已完成");
                $table->tinyInteger("refundStatus")->default(0)->comment("反结账状态 0 无反结账 1 部分反结账 2 全额反结账");
                $table->string("remark", 255)->default('')->comment("订单备注");
                $table->unsignedTinyInteger('isDeleted')->default(0)->comment('是否删除 1：已删除 0 未删除');
                $table->tinyInteger("payStatus")->default(0)->comment("支付状态 0 待支付 1 已支付");

                // 统一表字段
                $table->integer('createdAt')->default(0)->comment('创建时间');
                $table->string('createdBy')->default(0)->comment('创建人');
                $table->integer('createdByUid')->default(0)->comment('创建人');
                $table->integer('updatedAt')->default(0)->comment('修改时间');
                $table->integer('updatedByUid')->default(0)->comment('修改人');
                $table->string('updatedBy')->default(0)->comment('修改人');

                // 索引部分
                $table->primary('orderId', 'idx_orderId');        // 主键非自增
                $table->index(['orderId', 'brandId', 'shopId'], 'idx_orderId_brandId_shopId');  // 索引
                $table->index('createdAt', 'idx_createdAt');

                $table->collation = 'utf8mb4_general_ci';
                $table->comment   = '订单表_' . $name;
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
//        for ($i = 0; $i <= 99; $i++) {
//            $name = str_pad($i, 3, 0, STR_PAD_LEFT);
//            Schema::connection("mysqlOrder")->dropIfExists('order_' . $name);
//        }
    }
}
